home *** CD-ROM | disk | FTP | other *** search
- /*
- YARCSUP.C
- NetWare Alloy Archive Utility Support Procedures
- V4.42 02/04/84 by Mark Hurst
-
- For use with NetWare V4.n systems
-
- Copyright (C) 1983, 1984 by Novell, Inc.
- */
-
-
- #define LOCALBIT 0x80
- #define PERMNET 0x01
- #define TEMPNET 0x02
- #define NETBITS 0x03
-
- #define READBIT 0x01
- #define WRITEBIT 0x02
- #define OPENBIT 0x04
- #define CREATEBIT 0x08
- #define DELETEBIT 0x10
- #define OWNEDBIT 0x20
- #define SEARCHBIT 0x40
- #define MODIFYBIT 0x80
-
- #include "ctype.h"
- #include "stdio.h"
-
- #define VARPATH '^' - 'A'
-
- #define TRUE 1
- #define FALSE 0
-
- #define MAXVOLUMES 16
- #define MAXSPECS 100
- #define LISTSIZE 250
-
- #define ALLMODE 1
- #define MODMODE 2
- #define SELMODE 3
-
-
- extern FILE *log;
- extern int source, target; /* low level I/O file numbers */
- extern char actarget[20];
-
- extern int setvpath = FALSE; /* when TRUE => volume path set, continue archive */
-
- extern int printlog, spool, nprinter, logcopies;
- extern int startup;
-
- extern int system, continuous, finclude, fexclude;
- extern char *speclist[MAXSPECS];
- extern int speccount;
-
- extern int numberqualified, numberout;
- extern char *calloc(), *malloc();
-
- extern unsigned known, firsttypecheck, unusabledisk;
-
- typedef struct dosfcb {
- char drive;
- char fname[8];
- char fext[3];
- unsigned curblk;
- unsigned recsize;
- long size;
- unsigned date;
- char reserved[10];
- char relrec;
- char record[4];
- } FCB;
-
- typedef struct exdirfcb {
- char dummy;
- char exset;
- char res[5];
- char flags;
- char drive;
- char fname[8];
- char fext[3];
- char gap[17];
- char size[4];
- } ExDirFCB;
-
- typedef struct exdosfcb {
- char dummy;
- char exset;
- char res[5];
- char flags;
- char drive;
- char fname[8];
- char fext[3];
- unsigned curblk;
- unsigned recsize;
- long size;
- unsigned date;
- char reserved[10];
- char relrec;
- char record[4];
- } ExFCB;
-
- extern unsigned unitsize, freeunits, freeslots;
-
-
- extern int mode, bdrive, firstcopy;
-
- extern char pathstring[];
- extern char privmask;
-
- extern int listcount;
- typedef struct liststruct {
- struct liststruct *link;
- char name[12]; /* 1 too big for even allocation */
- char marked;
- char flags;
- long size; /* size of file in bytes */
- unsigned units; /* size of file in allocation units */
- } LISTNODE;
-
- extern LISTNODE *list[], *curnode;
-
- extern ExFCB sourcefile;
- extern ExFCB destfile;
-
-
- extern int logexists; /* flag; TRUE means there is an existing log file */
- extern FCB logfcb;
-
- int imin(a, b)
- int a,b;
- {
- if (a<b) return (a);
- else return (b);
- }
-
- unsigned umin(a, b)
- unsigned a,b;
- {
- if (a<b) return (a);
- else return (b);
- }
-
- long lmin(a, b)
- long a,b;
- {
- if (a<b) return (a);
- else return (b);
- }
-
- char inline[80];
- /* buffered input of strings from console. Forces first character to
- be non-space. returns first byte of input string. If break character
- detected, then the entire string is converted to 0x03, 0x00
- */
- char getstr(t, mx)
- int mx;
- char *t;
- {
- int i, j;
- char ch;
-
- i = 0;
- while ((ch=getch()) != 0x0D && ch != 0x03 && ch != 0x1B) {
- switch(ch) {
- case 0x08: /* backspace */
- if (i) {
- i--;
- cprintf("\10 \10");
- }
- break;
- default:
- if (ch < 0x20) break;
- if (!i && ch == 0x20) break;
- if (i >= mx) {putch(7); break;}
- putch(ch);
- t[i++] = ch;
- }
- }
- if (ch == 0x0D) {
- t[i] = 0;
- return (t[0]);
- }
- /* BREAK CHARACTER or ESCAPE DETECTED, CANCEL LINE and return char */
-
- t[0] = ch;
- t[1] = 0;
- return (ch);
- }
-
- yes(q)
- char *q;
- {
- char ch;
-
- ch = 'x';
- while (ch != 'Y' && ch != 'N') {
- cprintf("%s", q);
- ch = getstr(inline, 3);
- if (ch == 3) abort();
- ch = toupper(ch);
- if (!ch) {ch = 'N'; cprintf("No");}
- cprintf("\r\n");
- }
- if (ch == 'Y') return (TRUE);
- else return (FALSE);
- }
-
- invertword(pword)
- char *pword;
- {
- char temp;
-
- temp = pword[0];
- pword[0] = pword[1];
- pword[1] = temp;
- }
-
-
-
- struct PathOutStruct {
- int totallength;
- char fcode;
- char drive;
- char pathlen;
- char pathname[256];
- } path_out;
-
- struct PathInStruct {
- int totallength;
- char pathlen;
- char pathname[256];
- } path_in;
-
-
-
-
-
- /* SECTION TO SET THE DIRECTORY PATH MAPPINGS AND MODIFY THEM
- AS THE SUBDIRECTORY STRUCTURE IS TRAVERSED
- */
-
-
- NewTemp (drive, handle, path)
- int drive, handle;
- char *path;
- {
- int old, new, ccode, length;
- char flag, s[300], r[40];
-
- old = GetHandle (drive, &flag);
- s[1] = 0;
- s[2] = 19;
- s[3] = handle;
- s[4] = drive + 'A';
- s[5] = strlen(path);
- strcpy(&s[6], path);
- length = 4 + s[5];
- movmem(&length, s, 2);
-
- r[0] = 38;
- r[1] = 0;
- ccode = DirPath (s, r);
- if (ccode == 0xFE) LockError();
- else if (ccode) return (ccode);
- new = r[2];
- if (old != 0) {
- /*release old handle*/
- s[0] = 2;
- s[1] = 0;
- s[2] = 20;
- s[3] = old;
- DirPath (s, r);
- }
- return (0);
- }
-
-
-
- firstpath (line)
- char *line;
- /* SET PATH TO SPECIFICATION GIVEN BY USER */
- {
- int i, ccode;
- char ans[128], type, ctype;
- int fdrive, sdrive;
-
- compress(line);
- GetHandle (curdisk(), &ctype);
-
- if (*line == '\0') {
- if (ctype == LOCALBIT) {
- error("Local drives have no Subdirectories.");
- myexit(0);
- }
- fdrive = CurDisk();
- }
- else {
- if (line[1]==':' && (line[2]=='/' || line[2]==':' ||
- !line[2] || line[2]=='~' || line[2]=='.')) {
- fdrive = line[0] - 'A';
- GetHandle(fdrive, &type);
- if (type == LOCALBIT) {
- error("Local Drives have no Subdirectories.");
- myexit(0);
- }
- if (!type) {
- error("Specified drive does not exist.");
- myexit(0);
- }
- line = &line[2];
- }
- else if (ctype == LOCALBIT) {
- /* assume full pathname was specified */
- if (setpath(VARPATH, line)) {
- error("Local Drives have no Subdirectories.");
- myexit(0);
- }
- return;
- }
- else fdrive = CurDisk();
- }
- pathmodset (VARPATH, fdrive, line);
- }
-
- pathmodset(d, fd, mp)
- /* SET DRIVE D TO PATH OF DRIVE FD AS MODIFIED BY STRING MP */
- int d, fd;
- char *mp; /* pointer to path name string */
- {
- char ccode, handle, type;
-
- handle = GetHandle(fd, &type);
- ccode = NewTemp(d, handle, mp);
- if (ccode) {
- error("Error setting path mapping.");
- myexit(0);
- }
- }
-
-
- setpath (d, p)
- int d; char *p;
- /* SET DRIVE D TO PATH P */
- {
- return (NewTemp(d, 0, p));
- }
-
-
-
- getcurpath(d, s)
- int d;
- char *s;
- /* GET PATH OF DRIVE D INTO STRING S */
- {
- char ccode, type;
-
- ccode = getpath(GetHandle(d, &type), s);
- if (ccode) {
- error ("Error getting path mapping from.");
- myexit(0);
- }
- }
-
-
- getpath (handle, buffer)
- char handle;
- char *buffer;
- {
- char s[10], r[300], ccode;
- unsigned length;
-
- s[0] = 2;
- s[1] = 0;
- s[2] = 1;
- s[3] = handle;
- length = 295;
- movmem(&length, r, 2);
- ccode = DirPath(s, r);
- if (ccode == 0xFE) LockError();
- if (ccode) return (ccode);
- r[r[2] + 3] = 0;
- strcpy(buffer, &r[3]);
- return (0);
- }
-
-
-
- /* --------- STRING PRIMITIVES ----------- */
-
-
- compress(s)
- char *s;
- {
- char *c = s, ch;
-
- while (*s) if (!isspace(ch=*s++)) *c++ = ch;
- *c = '\0';
- }
-
-
- SetB (byte, buff, len)
- char byte, *buff;
- int len;
- {
- while (len-- > 0) *buff++ = byte;
- }
-
- CmpB (b1, b2, len)
- register char *b1, *b2; int len;
- {
- register int i;
-
- for (i=0; i<len; i++)
- if (*b1++ != *b2++) return (i);
- return (-1);
- }
-
- FindB (b, s, len)
- char b, *s;
- int len;
- {
- int i;
-
- for (i=0; i<len; i++) {
- if (b == s[i]) return (i);
- }
- return (-1);
- }
-
-
-
- conupper(t)
- char *t;
- {
- while (*t) {*t = toupper(*t); t++;}
- }
-
-
- LockError()
- {
- error("The Supervisor has the Directory System locked.");
- myexit(0);
- }
-
-
-
-
- /* ROUTINES TO GET SUBDIRECTORIES OF A SPECIFIC PATH */
-
-
- struct scandirstruct {
- int totallen;
- char fcode;
- char handle;
- char subdir[2];
- char speclength;
- char path;
- } scan;
-
- struct dirret {
- int maxlen;
- char subname[16];
- char createtime[4];
- char user_unique[4];
- char mask;
- char pad_junk;
- int subnum;
- } subinfo;
-
- intswap(i)
- char *i;
- {
- char temp;
-
- temp = i[0];
- i[0] = i[1];
- i[1] = temp;
- }
-
-
- getsubinfo(drive, subnum)
- int drive, subnum;
- /* get subdirectory d's info */
- {
- char ccode, type, swap[2];
- int swapsubnum;
-
- scan.totallen = 6;
- scan.fcode = 2;
- scan.handle = GetHandle(drive, &type);
- scan.subdir[0] = subnum >> 8;
- scan.subdir[1] = subnum & 0xFF;
- scan.speclength = 1;
- scan.path = '*';
- subinfo.maxlen = sizeof(struct dirret) - 2;
- ccode = DirPath (&scan, &subinfo);
- if (ccode == 0xFE) LockError();
- intswap(&subinfo.subnum);
- return (ccode);
- }
-
-
- checkrights(drive, pmask)
- char drive, pmask;
- {
- char ccode, mask, type;
- char s[20], r[10];
-
- s[0] = 3;
- s[1] = 0;
- s[2] = 3;
- s[3] = GetHandle(drive, &type);
- s[4] = 0; /* NULL PATH MOD SPEC, ASSUME CURRENT PATH (.) */
- r[0] = 8;
- r[1] = 0;
- ccode = DirPath (s, r);
- if (ccode == 0xFE) LockError();
- else if (ccode) return(FALSE);
- mask = r[2];
- if (mask == 0xFF) return (TRUE); /* OK TO BACK IT UP */
- if ((mask & pmask) == pmask) return (TRUE);
- else return (FALSE);
- }
-
- showfile(f)
- FCB *f;
- {
- int i, c;
- char ch;
-
- c = 0;
-
- for (i=0;i<8;i++) if ((ch=f->fname[i]) != 0x20) {putch(ch); c++;}
-
- if (f->fext[0] != 0x20) {
- putch('.'); c++;
- for (i=0;i<3;i++) if ((ch=f->fext[i]) != 0x20) {putch(ch);c++;}
- }
-
- c = 15 - c;
- for (i=0;i<c;i++) putch(' ');
- }
-
-
- addspecs(specs)
- char *specs;
- {
- int ix, stix;
-
- compress(specs); conupper(specs);
- ix = 0;
- while (specs[ix]) {
- stix = ix; /* save start of scan */
- while (specs[ix] && specs[ix] != ',') ix++;
- if (specs[ix]) {
- specs[ix] = 0; /* null out the comma */
- addspec(&specs[stix]);
- ix++;
- }
- else if (ix != stix) addspec(&specs[stix]);
- }
- }
-
- addspec(spec)
- char *spec;
- {
- char *s = malloc(12), ch;
- int si, di, ix;
-
- si = di = 0;
- setmem(s, 11, 0x20);
- s[11] = 0;
-
- /* DO KLUGE TO MATCH DOS WILD MATCH-- "*" matches everything,
- but "*." matches all without any extensions. */
- if (!strcmp("*", spec)) setmem(&s[8], 3, '?');
-
- while (di < 8) {
- ch = spec[si];
- if (ch == '.') {
- di = 8; /* end of file name, go on to get extension */
- }
- else if (!ch) {
- di = 11; /* end of file spec */
- }
- else if (ch != '*') {
- s[di++] = ch;
- si++;
- }
- else {
- for (ix = di; ix < 8; ix++) s[ix] = '?';
- di = 8;
- while ((ch=spec[si]) && ch != '.') si++;
- }
- }
-
- if (speccount >= MAXSPECS) {
- cprintf("File spec list full, entry \"%s\" ignored.\r\n\7",spec);
- free(s);
- return;
- }
- if (spec[si] && spec[si] != '.') {
- /* IF MORE THAN 8 CHARS IN A ROW, IGNORE SPEC AS ILLEGAL */
- cprintf("File spec \"%s\" illegal; entry ignored.\r\n\7",spec);
- free(s);
- return;
- }
-
- speclist[speccount++] = s; /* ADD SPEC TO DYNAMIC LIST */
- if (!spec[si]) return; /* no extension, return ok */
-
- si++; /* skip '.' */
-
- while (di < 11) {
- ch = spec[si];
- if (!ch) {
- di = 11; /* end of file spec */
- }
- else if (spec[si] != '*') {
- s[di++] = spec[si++];
- }
- else {
- for (ix = di; ix < 11; ix ++) s[ix] = '?';
- di = 11;
- si++;
- }
- }
- }
-
-
- inexquery()
- {
- char specs[80];
-
- finclude, fexclude = FALSE;
- speccount = 0;
-
- if (!yes(
- "Do you want to select or ignore files based on certain file specs? (Y/N) "))
- return;
-
- cprintf("Enter list of file specs to be used for selecting files\r\n");
- cprintf("or <RETURN> if none. Multiple lines may be entered.\r\n");
-
- while (speccount < MAXSPECS) {
- cprintf("> ");
- if (getstr(specs, 77) == 3) abort();
- cprintf("\r\n");
- if (specs[0] == '\0') break;
- finclude = TRUE;
- addspecs(specs);
- }
-
- if (finclude) return;
-
- /* ENTER EXCLUSION LIST INSTEAD */
- cprintf("Enter list of file specs to be used for ignoring files\r\n");
- cprintf("or <RETURN> if none. Multiple lines may be entered.\r\n");
- while (1) {
- cprintf("> ");
- if (getstr(specs, 77) == 3) abort();
- cprintf("\r\n");
- if (specs[0] == '\0') break;
- fexclude = TRUE;
- addspecs(specs);
- }
- }
-
- include(filename)
- char *filename;
- {
- if (!finclude) return (TRUE); /* accept any file if no specifics given*/
-
- /* RETURN TRUE IF THIS FILE MATCHES ANY OF THE INCLUSION LIST SPECS */
- return (fmatch(filename));
- }
-
- exclude(filename)
- char *filename;
- {
- if (!fexclude) return (FALSE); /* don't reject any file */
-
- /* RETURN TRUE IF THIS FILE MATCHES ANY OF THE EXCLUSION LIST SPECS */
- return (fmatch(filename));
- }
-
- fmatch(filename)
- char *filename;
- {
- char *spec;
- int f, ix;
-
- for (f=0; f < speccount; f++) {
- spec = speclist[f];
- for (ix=0; ix < 11; ix++) {
- if (spec[ix] != '?' && spec[ix] != filename[ix])
- goto nextspec;
- }
- return (TRUE);
- nextspec: ;
- }
- return (FALSE);
- }